using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;

namespace VOL.demo.Services
{
    public partial class StockInOrderItemModelService
    {
        /// <summary>
        /// 批量添加入库明细
        /// </summary>
        public async Task<bool> AddItemsAsync(List<StockInOrderItemModel> items)
        {
            try
            {
                Console.WriteLine($"Service层：准备添加 {items?.Count ?? 0} 条入库明细");
                return await _repository.AddItemsAsync(items);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Service层批量添加入库明细失败：{ex.Message}");
                Console.WriteLine($"详细堆栈：{ex.ToString()}");
                throw;  // 向上抛出，让事务层能捕获
            }
        }

        /// <summary>
        /// 根据入库单号获取明细
        /// </summary>
        public async Task<List<StockInOrderItemModel>> GetItemsByStockInCodeAsync(string stockInCode)
        {
            try
            {
                return await _repository.GetItemsByStockInCodeAsync(stockInCode);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"获取入库明细失败：{ex.Message}");
                return new List<StockInOrderItemModel>();
            }
        }

        /// <summary>
        /// 根据条件查询入库明细列表
        /// </summary>
        public async Task<List<StockInOrderItemModel>> FindAsync(Expression<Func<StockInOrderItemModel, bool>> predicate, bool filterDeleted = true)
        {
            return await repository.FindAsync(predicate, filterDeleted);
        }
    }
}


